<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<section>
    <input id="input" type="text" placeholder="请输入姓名">
    <button id="btn">进入聊天室</button>
</section>
<script>
    ;(function () {
        const domInput = document.querySelector('#input');
        const domBtn = document.querySelector('#btn');

        function init() {
            addEvent();
        }

        function addEvent() {
            domBtn.addEventListener('click', entry, false);
        }

        function entry() {
            const name = domInput.value.trim();
            if (name.length < 1) {
                alert('名字不能小于1位');
            } else {
                localStorage.setItem('username', name);
                location.href = './index.html';
            }
        }

        init();
    })();
</script>
</body>
</html>